import * as types from '../../mutation-types'
import lazyLoading from './lazyLoading'
import equipment from './equipment'
// show: meta.label -> name
// name: component name
// meta.label: display label

const state = {
  items: [
    {
      name: '首页',
      path: '/',
      meta: {
        icon: 'fa-home',
        link: 'Home.vue'
      },
      component: lazyLoading('Home')
    },
    equipment,
    {
      name: '用户监控',
      path: '/user',
      meta: {
        icon: 'fa-tachometer',
        link: 'page/user.vue'
      },
      component: lazyLoading('page/user')
    },
    {
      name: 'JOB',
      path: '/job',
      meta: {
        icon: 'fa-paragraph ',
        link: 'page/job.vue'
      },
      component: lazyLoading('page/job')
    },
    {
      name: '日志查询',
      path: '/log',
      meta: {
        icon: 'fa-search',
        link: 'page/log.vue'
      },
      component: lazyLoading('page/log')
    },
    {
      name: '关联查询',
      path: '/relation',
      meta: {
        icon: 'fa-chain',
        link: 'page/relation.vue'
      },
      component: lazyLoading('page/relation')
    },
    {
      name: '系统配置',
      path: '/set',
      meta: {
        icon: 'fa-cogs',
        link: 'page/set.vue'
      },
      component: lazyLoading('page/set')
    }
  ]
}

const mutations = {
  [types.EXPAND_MENU] (state, menuItem) {
    if (menuItem.index > -1) {
      if (state.items[menuItem.index] && state.items[menuItem.index].meta) {
        state.items[menuItem.index].meta.expanded = menuItem.expanded
      }
    } else if (menuItem.item && 'expanded' in menuItem.item.meta) {
      menuItem.item.meta.expanded = menuItem.expanded
    }
  }
}

export default {
  state,
  mutations
}
